package MyApp.Controller
{
	import MyApp.Model.Well;
	import MyApp.Model.WellGroup;
	import MyApp.Model.proxy.WellGroupProxy;
	
	import components.wellGroup.WellGroupWindow;
	
	import custom.pager.Pager;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	
	public class WellGroupCommand extends SimpleCommand
	{
		public function WellGroupCommand()
		{
			super();
		}
		private function get proxy():WellGroupProxy{
			if(!facade.hasProxy(WellGroupProxy.NAME)){
				facade.registerProxy(new WellGroupProxy(WellGroupProxy.NAME));
			}
			return facade.retrieveProxy(WellGroupProxy.NAME) as WellGroupProxy;
		}
		override public function execute(notification:INotification):void{
			switch(notification.getName()){
				case WellGroupWindow.DO_REFRESH:
					proxy.loadList(Pager(notification.getBody()));
					break;
				case WellGroupWindow.DO_ADD_WELL_GROUP:
					proxy.addWellGroup(notification.getBody() as WellGroup);
					break;
				case WellGroupWindow.DO_ADD_WELL:
					proxy.addWell(notification.getBody());
					break;
				case WellGroupWindow.DO_REFRESH_WELL:
					proxy.loadWellByGroup(notification.getBody());
					break;
				case WellGroupWindow.DO_SAVE_WELL_GROUP:
					proxy.updateWellGroup(notification.getBody() as WellGroup);
					break;
				case WellGroupWindow.DO_BIND:
					proxy.bindWell(notification.getBody());
					break;
				case WellGroupWindow.DO_UNBIND:
					proxy.unbindWell(notification.getBody());
					break;
				case WellGroupWindow.DO_DELETE:
					proxy.deleteWellGroup(notification.getBody());
					break;
				case WellGroupWindow.DO_DELETE_WELL:
					proxy.deleteWell(notification.getBody());
					break;
			}
		}
	}
}